<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表 </el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-input placeholder="请输入内容"
                suffix-icon="el-icon-search"
                style="width:300px">
      </el-input>

      <el-table :data="orderList"
                style="width: 100%">
        <el-table-column type="index"
                         label="序号">
        </el-table-column>
        <el-table-column prop="order_number"
                         label="订单编号"
                         width="180">
        </el-table-column>
        <el-table-column prop="order_price"
                         label="订单编号"
                         width="180">
        </el-table-column>
        <el-table-column prop="pay_status"
                         label="是否付款">
          <template slot-scope="scope">
            <el-tag type="primary"
                    v-if="scope.row.pay_status == 0">已付款</el-tag>
            <el-tag type="danger"
                    v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send"
                         label="是否发货">
        </el-table-column>
        <el-table-column prop="create_time"
                         label="下单时间">
          <template slot-scope="scope">
            {{scope.row.create_time | dateFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini"
                       type="primary"
                       @click="editOrder(scope.row.order_id)"
                       icon="el-icon-edit"></el-button>
            <el-button size="mini"
                       type="success" @click="showProgress(scope.row.order_id)"
                       icon="el-icon-location"></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区 -->
      <el-pagination @size-change="handleSizeChange"
                     @current-change="handleCurrentChange"
                     :current-page="pageInfo.curPage"
                     :page-sizes="pageInfo.pageSizes"
                     :page-size="pageInfo.pageSize"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="pageInfo.totalRecord">
      </el-pagination>
    </el-card>

    <!-- 修改地址对话框 -->
    <el-dialog title="修改地址"
               :visible.sync="editAddressVisibale"
               width="50%">
      <el-form :model="editAddressForm"
               status-icon
               :rules="editAddressRule"
               ref="editAddressRef"
               label-width="100px"
               class="demo-ruleForm">
        <el-form-item label="省/市/区(县)"
                      prop="address1">
          <!-- <el-input type="text"
                    v-model="editAddressForm.address1"
                    autocomplete="off"></el-input> -->
          <el-cascader :options="cityData"
                       v-model="editAddressForm.address1">

          </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址"
                      prop="address2">
          <el-input type="text"
                    v-model="editAddressForm.address2"
                    autocomplete="off"></el-input>
        </el-form-item>
        <el-button type="info">取消</el-button>
        <el-button type="primary" @click="editAddress">确定</el-button>
      </el-form>
    </el-dialog>

    <!-- 展示物流信息对话框 -->
    <el-dialog title="修改地址"
               :visible.sync="showProgressVisible"
               width="50%">
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata'
export default {
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orderList: [],
      pageInfo: {
        curPage: 1,
        pageSize: 10,
        totalRecord: 0,
        pageSizes: [10, 20, 30, 40, 50]
      },
      editAddressVisibale: false,
      editAddressForm: {
        address1: '',
        address2: ''
      },
      editAddressRule: {
        address1: [{ required: true, message: '请选择地址', trigger: 'blur' }],
        address2: [
          { required: true, message: '请填写详细地址', trigger: 'blur' }
        ]
      },
      cityData: cityData,
      showProgressVisible: false
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取数据失败')
      }
      this.orderList = res.data.goods
      this.pageInfo.curPage = parseInt(res.data.pagenum)
      this.pageInfo.totalRecord = res.data.total
    },
    handleSizeChange () {},
    handleCurrentChange () {},
    editOrder (orderId) {
      this.editAddressVisibale = true
    },
    editAddress (orderId) {
      this.$refs.editAddressRef.validate(vali => {
        if (!vali) {
          return false
        }
      })
    },
    async showProgress (orderId) {
    //   const { data: res } = await this.$http.get('/kuaidi/1106975712662')
    //   console.log(res)
    }
  }
}
</script>

<style>
</style>
